package util;

import android.database.Cursor;

import java.util.Map;

/**
 * Created by Administrator on 2016/4/11.
 */
public class PageDao {
    public static void deleteDataByTxtId(int txtId){
        String sql="delete from page where txt_id=?";
        Global.util.getWritableDatabase().execSQL(sql,new Object[]{txtId});
    }

    public static void insertData(Map<String,Object> map){
        String sql="insert into page(txt_id,content,page_num) values(?,?,?)";
        Global.util.getWritableDatabase().execSQL(sql,new Object[]{map.get("txtId"),map.get("content"),map.get("pageNum")});
    }


    private static String content;
    public static String getDataByTxtIdAndNowPage(int txtId,int pageNum){
        String sql="select content from page where txt_id=? and page_num=?";
        Cursor c=Global.util.getReadableDatabase().rawQuery(sql,new String[]{txtId+"",pageNum+""});
        c.moveToFirst();
        while (!c.isAfterLast()) {
            content = c.getString(0);
            c.moveToNext();
        }
        c.close();
        return content;
    }

    public static int getPageCount(int id){
        String sql="select count(*) from page where txt_id=?";
        Cursor c=Global.util.getReadableDatabase().rawQuery(sql,new String[]{id+""});
        c.moveToFirst();
        int pageNum=c.getInt(0);
        c.close();
        return pageNum;
    }

}
